﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.IO;

namespace Bing.Toolkit.Web
{
    /// <summary>
    /// 常用路径获取
    /// </summary>
    public static class ApplicationPath
    {
        /// <summary>
        /// 获取当前应用程序的物理路径
        /// </summary>
        public static string AbsolutePhysicsPath
        {
            get
            {
                return System.AppDomain.CurrentDomain.BaseDirectory;
            }
        }
        /// <summary>
        /// 获取当前WEB应用程序的虚拟根路径
        /// </summary>
        public static Uri VirtualWebRoot
        {
            get
            {
                return new Uri(System.Web.HttpRuntime.AppDomainAppVirtualPath);
            }
        }
        /// <summary>
        /// 获取当前应用程序的绝对根路径(相当于纯域名)
        /// </summary>
        public static Uri AbsoluteWebRoot
        {
            get
            {
                HttpContext context = HttpContext.Current;
                if (context == null)
                    throw new System.Net.WebException("The current HttpContext is null");

                if (context.Items["absoluteurl"] == null)
                    context.Items["absoluteurl"] = new Uri(context.Request.Url.GetLeftPart(UriPartial.Authority));
                return context.Items["absoluteurl"] as Uri;
            }
        }
    }
}
